var platform = null;

"undefined" != typeof wx && (platform = "wx"), "undefined" != typeof my && (platform = "my");
const miniShopPlugin = requirePlugin('mini-shop-plugin');
var modules = [{
  name: "helper",
  file: "./utils/helper.js"
}, {
  name: "const",
  file: "./core/const.js"
}, {
  name: "getConfig",
  file: "./core/config.js"
}, {
  name: "page",
  file: "./core/page.js"
}, {
  name: "request",
  file: "./core/request.js"
}, {
  name: "core",
  file: "./core/core.js"
}, {
  name: "api",
  file: "./core/api.js"
}, {
  name: "getUser",
  file: "./core/getUser.js"
}, {
  name: "setUser",
  file: "./core/setUser.js"
}, {
  name: "login",
  file: "./core/login.js"
}, {
  name: "trigger",
  file: "./core/trigger.js"
}, {
  name: "uploader",
  file: "./utils/uploader.js"
}, {
  name: "orderPay",
  file: "./core/order-pay.js"
}],
  args = {
    _version: "2.8.9",
    platform: platform,
    query: null,
    onLaunch: function () {
      miniShopPlugin.initApp(this, wx);
      this.getStoreData();
    },
    onShow: function (e) {
      // var obj = wx.getLaunchOptionsSync()
      // var  scene_value = obj.scene;
      // console.log('启动onshow',obj)
      // wx.setStorageSync('scene_value',scene_value)
      const updateManager = wx.getUpdateManager()
      updateManager.onCheckForUpdate(function (res) {
        // 请求完新版本信息的回调
        console.log(res.hasUpdate)
      })
      updateManager.onUpdateReady(function () {
        wx.showModal({
          title: '更新提示',
          content: '新版本已经准备好，是否重启应用？',
          success: function (res) {
            if (res.confirm) {
              // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
              // wx.clearStorage()
              // try {
              //   wx.clearStorageSync()
              // } catch (e) {
              //   // Do something when catch error
              // }
              updateManager.applyUpdate()

            }
          }
        })
      })
      updateManager.onUpdateFailed(function () {
        // 新版本下载失败
        // wx.showToast({
        //   title: '新版本更新失败，请检查网络是否有异常',
        //   icon: 'success',
        //   duration: 2000
        // })
      })
      e.scene && (this.onShowData = e), e && e.query && (this.query = e.query), this.getUser() && this.trigger.run(this.trigger.events.login);
    },
    is_login: !1,
    login_complete: !1,
    is_form_id_request: !0
  };

for (var i in modules) args[modules[i].name] = require("" + modules[i].file);

var _web_root = args.api.index.substr(0, args.api.index.indexOf("/index.php"));

args.webRoot = _web_root, args.getauth = function (t) {
  var s = this;
  if ("my" == s.platform) {
    if (t.success) {
      var e = {
        authSetting: {}
      };
      e.authSetting[t.author] = !0, t.success(e);
    }
  } else s.core.getSetting({
    success: function (e) {
      console.log(e), void 0 === e.authSetting[t.author] ? s.core.authorize({
        scope: t.author,
        success: function (e) {
          t.success && (e.authSetting = {}, e.authSetting[t.author] = !0, t.success(e));
        }
      }) : 0 == e.authSetting[t.author] ? s.core.showModal({
        title: "是否打开设置页面重新授权",
        content: t.content,
        confirmText: "去设置",
        success: function (e) {
          e.confirm ? s.core.openSetting({
            success: function (e) {
              t.success && t.success(e);
            },
            fail: function (e) {
              t.fail && t.fail(e);
            },
            complete: function (e) {
              t.complete && t.complete(e);
            }
          }) : t.cancel && s.getauth(t);
        }
      }) : t.success && t.success(e);
    }
  });
}, args.getStoreData = function () {
  var s = this,
    e = this.api,
    o = this.core;
  s.request({
    url: e.default.store,
    success: function (t) {
      0 == t.code && (o.setStorageSync(s.const.STORE, t.data.store), o.setStorageSync(s.const.STORE_NAME, t.data.store_name),
        o.setStorageSync(s.const.SHOW_CUSTOMER_SERVICE, t.data.show_customer_service), o.setStorageSync(s.const.CONTACT_TEL, t.data.contact_tel),
        o.setStorageSync(s.const.SHARE_SETTING, t.data.share_setting), s.permission_list = t.data.permission_list,
        o.setStorageSync(s.const.WXAPP_IMG, t.data.wxapp_img), o.setStorageSync(s.const.WX_BAR_TITLE, t.data.wx_bar_title),
        o.setStorageSync(s.const.ALIPAY_MP_CONFIG, t.data.alipay_mp_config), o.setStorageSync(s.const.STORE_CONFIG, t.data),
        setTimeout(function (e) {
          s.config = t.data, s.configReadyCall && s.configReadyCall(t.data);
        }, 1e3));
    },
    complete: function () { }
  });
};

var app = App(args);